package org.spring.flower.student.controller;


import org.spring.flower.resume.entity.Info;
import org.spring.flower.resume.feign.RemoteInfoService;
import org.spring.flower.student.entity.StuInfo;
import org.spring.flower.student.service.IStuInfoService;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LianSong
 * @since 2020-03-08
 */
@RestController
@RequestMapping("/student/stuInfo")
public class StuInfoController {

    /*自动注册nocas的注册中心（因为这个对象里面就存在我需要的服务和地址）*/
    @Resource
    private DiscoveryClient discoveryClient;
    @Resource
    private IStuInfoService stuInfoService;
    @Resource
    private RestTemplate restTemplate;
    @Resource
    private RemoteInfoService remoteInfoService;


    @GetMapping("/list")
    public List<StuInfo> list(){
        return stuInfoService.list();
    }


    @GetMapping("/instances")
    public List<ServiceInstance> getInstances(){
        return discoveryClient.getInstances("student-service");
    }

    @GetMapping("/resume/list")
    public List<Info> resumeList(){
        return restTemplate.getForObject("http://resume-service/resume/info/list", List.class);
    }

    @GetMapping("/feign/resume/list")
    public List<Info> feignResumeList(){
        return remoteInfoService.list();
    }
}
